import axios from 'axios'

axios.interceptors.response.use(response => response, error => Promise.resolve(error.response))

function checkStatus(response) {
    console.log(response)
}

function checkCode(res) {
    return res
}

export default {
    post(url, data) {
        return axios({
            method: 'post',
            url: url,
            data: `data=${JSON.stringify(data)}`,
            timeout: "30000",
            // withCredentials:withCredentials,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        })
    },
    get(url, params) {
        return axios({
            method: 'get',
            url:  url,
            params,
            timeout: "30000",
            // withCredentials:withCredentials,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
        }).then(checkStatus).then(checkCode)
    }
}
